package com.yj.lottery_system.dao.mapper;

import com.yj.lottery_system.dao.dataObject.ActivityPrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityPrizeMapper {
    /**
     * 批量插入信息
     * @param activityPrizeDOList
     * @return
     */

    @Insert("<script> " +
            "insert into activity_prize  " +
            "(activity_id, prize_amount, prize_id, prize_tiers,status) " +
            "values <foreach item = 'item' collection='items' index='index' separator=','  > " +
            " (#{item.activityId},#{item.prizeAmount},#{item.prizeId},#{item.prizeTiers},#{item.status}) " +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int batchInsert(@Param("items") List<ActivityPrizeDO> activityPrizeDOList);

    /**
     * 根据活动id 查活动关联奖品信息
     * @param activityId
     * @return
     */
    @Select("select * from activity_prize where activity_id = #{activityId}")
    List<ActivityPrizeDO> selectByActivityId(@Param("activityId") Long activityId);
    /**
     * 根据活动id与奖品id组成唯一索引 查活动关联奖品信息
     * @param activityId
     * @return
     */
    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByAPId(@Param("activityId")Long activityId, @Param("prizeId")Long prizeId);

    /**
     *活动activityId下 奖品RUNNING状态 的个数
     * @param activityId 活动id
     * @param status 奖品状态
     * @return
     */
    @Select("select count(1) from activity_prize where activity_id = #{activityId} and status = #{status}")
    int countPrize(@Param("activityId")Long activityId, @Param("status")String status);

    /**
     * 更新被抽取奖品状态
     * @param activityId 活动id
     * @param prizeId 奖品id
     * @param status 奖品状态
     */
    @Update(("update activity_prize set status = #{status} where activity_id = #{activityId} and prize_id = #{prizeId}"))
    void updateStatus(@Param("activityId")Long activityId,  @Param("prizeId")Long prizeId,  @Param("status")String status);
}
